<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>2-5秒跳转百度</title>
    <script>
        //1.页面加载成功后，设置执周期执行器，每个1秒调用指定函数
        let interId;
        onload=function(){
            //设置单次执行器
            interId= setInterval(changeTime,1000);
        }
        let time=5;
        //编写changeTime函数
        function changeTime() {
            time--;
            let spObj = document.getElementById("baidu");
                spObj.innerText=time;
            if (time==0){
                //清除执行器
                clearInterval(interId);
                //实现页面跳转
                location.href="https://www.baidu.com";
            }

        }

    </script>
</head>

<body>

    <font color="red" size="50px"><span id="baidu">5</span>秒后跳转百度！</font>

</body>
</html>